<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/9
  Time: 11:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
</head>
<center>
<body>
<%--多条件查询--%>
<form class="layui-form" action="${pageContext.request.contextPath}/admin/list" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">账 号</label>
        <div class="layui-input-inline">
            <input type="text" name="account" value="${params.account}">
        </div>
        <label class="layui-form-label">状 态</label>
        <div class="layui-input-inline">
            <input type="radio" name="status">
                 <option value="1" <c:if test="${params.status=='1'}">selected</c:if>>正常</option>
                 <option value="0" <c:if test="${params.status=='0'}">selected</c:if>>注销</option>
            </input>
        </div>
         <label class="layui-form-label">姓名</label>
         <div class="layui-input-inline">
            <input type="text" name="name" value="${params.name}">
            <input type="text" name="pageNum" value="1">
            <input type="text" name="pageSize" value="1">
            <input type="submit" value="查询">
         </div>
    </div>

<a href="${pageContext.request.contextPath}/admin/toadd">新增</a>
   <table border="1px">
       <thead>
       <tr>
           <td>ID</td>
           <td>账号</td>
           <td>用户名</td>
           <td>电话</td>
           <td>邮箱</td>
           <td>性别</td>
           <td>状态</td>
           <td>角色</td>
           <td>头像</td>
           <td>操作人</td>
           <td>操作</td>
       </tr>
       </thead>
       <tbody>
       <c:forEach items="${page.list}" var="admin">
       <tr>
           <td>${admin.id}</td>
           <td>${admin.account}</td>
           <td>${admin.name}</td>
           <td>${admin.phone}</td>
           <td>${admin.email}</td>
           <td>${admin.sex=="1"?"男":admin.sex=="2"?"女":"未知"}</td>
           <td>${admin.status=="0"?"注销":"正常"}</td>
           <td>${admin.role.rolename}</td>
           <td><img style="width: 20px;height: 20px;border-radius: 50%;"
                    src="${pageContext.request.contextPath}${admin.headpic}" >
               <a href="${pageContext.request.contextPath}/admin/headpicDowmload?filename=${fn:replace(admin.headpic,"/head/","")}">下载</a>
           </td>
           <td>${admin.operatorAdmin.account}</td>
           <td><a href="">修改</a>
               <a href="javascript:deleteAdmin(${admin.id})">删除</a>
               <a href="${pageContext.request.contextPath}/admin/headpic.jsp?id=${admin.id}">修改头像</a></td>
       </tr>
       </c:forEach>
       </tbody>
   </table>
   <div>
       <a href="javascript:goPage(${page.pageNum-1})">上一页</a>
       <a href="javascript:goPage(${page.pageNum+1})">上一页</a>
       当前页：${page.pageNum},总记录数：${page.total},总页数：${page.pages}
   </div>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.min.js"></script>
<script>
    function goPage(num) {
        $("input[name='pageNum']").val(num);
        $("form").submit();
    }
    function deleteAdmin(id) {
        if (confirm("确认要删除此条数据！")){
        $.ajax({
            url:"${pageContext.request.contextPath}/admin/delete",
            type:"get",
            data:{"id":id},
            dataType:"json",
            success:function (result) {
                 alert("删除成功，返回结果为"+JSON.stringify(result));
                 //重新加载页面或跳转页面
                 window.location.reload();
            },
            error:function () {
                 alert("删除失败！")
            }
        })
    }
    }
</script>
</form>
</body>
</center>
</html>
